//管理miste功能相关状态数据的vuex模块

import {RECEIVE_USER,RESET_USER} from '../mutation-types'
const state={
    user:{}//用户信息
}
const mutations={
    [RECEIVE_USER](state,{user}){
        state.user = user
    },
    [RESET_USER](state){
        state.user={}
    },
}
const getters={}
const actions={
     //保存user的同步action
     saveUser({commit},user){
        //取出token 将token保存到loaclStorage中
        // const token = user.token
        // localStorage.setItem('token',token)
        // commit(RECEIVE_TOKEN,{token})
        //不用user:{}这么包以下mutation那边没法根据名子取
        commit(RECEIVE_USER,{user})
    },

    //退出登录
    logout({commit}){
        commit(RESET_USER)
    },
    
}
export default{
    state,
    mutations,
    actions,
    getters
}